package com.mall;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.sql.DataSource;
import java.sql.Connection;

/**
 * 电商网站主启动类
 * 
 * @author Mall Team
 * @version 1.0
 */
@SpringBootApplication
@MapperScan("com.mall.mapper")
public class MallBackendApplication implements CommandLineRunner {
    
    @Autowired
    private DataSource dataSource;
    
    public static void main(String[] args) {
        SpringApplication.run(MallBackendApplication.class, args);
        System.out.println("=================================");
        System.out.println("  淘宝式电商网站启动成功！");
        System.out.println("  访问地址: http://localhost:8080");
        System.out.println("=================================");
    }
    
    @Override
    public void run(String... args) throws Exception {
        // 测试数据库连接
        try (Connection connection = dataSource.getConnection()) {
            System.out.println("数据库连接成功: " + connection.getMetaData().getURL());
        } catch (Exception e) {
            System.err.println("数据库连接失败: " + e.getMessage());
            throw e;
        }
    }
}